package com.qyhl.webtv.commonlib.item.fuquan;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.TextView;

import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.R;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

public class ItemFuQuanCircleText implements ItemViewDelegate<GlobalNewsBean> {
    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_fuquan_circle_text;
    }

    @Override
    public boolean isForViewType(GlobalNewsBean item, int position) {
        return "15".equals(item.getType()) && item.getNewsStyle() == 1;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ViewHolder holder, GlobalNewsBean bean, int position) {
        holder.setText(R.id.title, bean.getTitle());

        TextView topName = holder.getView(R.id.topic_name);
        if (StringUtils.isNotEmpty(bean.getOrigin())) {
            topName.setVisibility(View.VISIBLE);
            topName.setText("#" + bean.getOrigin() + "#");
        } else {
            topName.setVisibility(View.GONE);
        }


        TextView nickName = holder.getView(R.id.nickName);
        if (StringUtils.isNotEmpty(bean.getCatalogId())) {
            nickName.setText(bean.getCatalogId());
        } else {
            nickName.setText("匿名");
        }

        TextView scan = holder.getView(R.id.scan);
        try {
            int minPlay = Integer.parseInt(CommonUtils.getInstance().getMinPlay());
            if (minPlay == 0) {
                scan.setVisibility(View.GONE);
            } else {
                //判断评论数是否大于最少浏览数
                if (StringUtils.isEmpty(bean.getScanNum() + "")) {
                    scan.setVisibility(View.GONE);
                } else if (bean.getScanNum() >=
                        minPlay) {
                    scan.setText(StringUtils.transformNum(bean.getScanNum() + "") + "阅");
                    scan.setVisibility(View.VISIBLE);
                } else {
                    scan.setVisibility(View.GONE);
                }
            }

        } catch (Exception e) {
            scan.setVisibility(View.GONE);
        }

    }
}
